package edu.cuit.avatar.common;

/**
 * @author <a href="mailto:1020zhaodan@163.com">Adan</a>
 * @version 1.0
 * @date 2025/7/26 9:59
 */
public class StringUtils {

    /**
     * 将下划线转为驼峰结果
     * number_of_year ===> numberOfYear
     * @param str 源字符串
     * @return 驼峰结构字符串
     */
    public static String mapUnderscoreToCamelCase(String str){
        if(isBlank(str)) return str;
        String[] words = str.split("_");
        String dest = words[0];
        for(var i = 1; i < words.length; i++)
            dest += Character.toUpperCase(words[i].charAt(0)) + words[i].substring(1);
        return dest;
    }

    /**
     * 将驼峰转为下划线
     * numberOfYear ===> number_of_year
     * @param str
     * @return
     */
    public static String mapCamelCaseToUnderscore(String str){
        return str.replaceAll("([a-z])([A-Z]+)","$1_$2").toLowerCase();
    }

    public static boolean isBlank(String str){
        return str == null || "".equals(str);
    }


}
